/* 
 * Copyright (C) 2012 Martin Řehánek <rehan at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Je to konteiner pro jeden track
 * tj. zobrazuje jeho nazev, sipky pro pohyb v ramci playlistMenu
 * a "krizek" pro odstraneni z playlistMenu
 */

//TODO: mozna nechat v ramci PlaylistMenu
goog.provide('kramerius.audio.ui.playlist.TrackComponent');

goog.require('goog.ui.Container');
goog.require('goog.ui.Tooltip');
goog.require('goog.ui.Component');
goog.require('goog.ui.Control');

/*
 * @param {goog.ui.ControlContent} content Text caption or DOM structure
 *     to display as the content of the component (if any).
 * @param {goog.ui.ControlRenderer=} opt_renderer Renderer used to render or
 *     decorate the component; defaults to {@link goog.ui.ControlRenderer}.
 * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper, used for
 *     document interaction.
 * @constructor
 * @extends {goog.ui.Control}
 * @constructor
 */
//kramerius.audio.ui.playlist.TrackComponent = function(track, trackMenu){
//kramerius.audio.ui.playlist.TrackComponent = function(track, trackMenu){
kramerius.audio.ui.playlist.TrackComponent = function(content, opt_renderer, opt_domHelper, track){
    //this.track_ = undefined;
    this.track_ = track;
    this.trackMenu_ = undefined; //TODO: dodat v konstruktoru
    //this.trackContainer_ = undefined;
    //this.container_ = undefined;
    this.container_ = this.initContainer_();
    
    //this.trackContainer_ = this.initContainer_();
    
    //veci pro control
    goog.ui.Control.call(this, 
        content, 
        opt_renderer || goog.ui.ControlRenderer.getInstance(),
        opt_domHelper);
    
    
    /**
     * Event handler for this object.
     * @type goog.events.EventHandler
     * @private
     */
    this.eh_ = new goog.events.EventHandler(this);
    
    /**
     * Keyboard handler for this object. This object is created once the 
     * component's DOM element is known.
     *
     * @type goog.events.KeyHandler|Null
     * @private
     */
    this.kh_ = null;
};
goog.inherits(kramerius.audio.ui.playlist.TrackComponent, goog.ui.Control);

//kramerius.audio.ui.playlist.TrackComponent.prototype.setTrack = function(track){
//    this.track_ = track;   
//    
//}


kramerius.audio.ui.playlist.TrackComponent.prototype.createDom = function(){
    //this.trackContainer_ = this.initContainer_();
    console.log("TrackComponent: createDom: " + trackContainer);
    return trackContainer.createDom();
    console.log("TrackComponent: dom created");
}


//do hajzlu, Container neni potomek Control.
//TODO: muzu zkusit vytvorit vlastni control

/** @private */
kramerius.audio.ui.playlist.TrackComponent.prototype.initContainer_ = function(){
    console.log("TrackComponent: creating container");
    var container = new goog.ui.Container(goog.ui.Container.Orientation.HORIZONTAL);
    //var container = new goog.ui.Container(goog.ui.Container.Orientation.VERTICAL);
    
    //title
    var titleCtrl = new goog.ui.Control(this.track_.getTitle());
    titleCtrl.addClassName('playlist-item-title');
    //titleCtrl.setId(this.title_);
    titleCtrl.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
    container.addChild(titleCtrl, true);
    
    //button up
    var moveUpCtrl = new goog.ui.Control();
    console.log("MOVE_UP");
    kramerius.audio.debug_utils.appendDebugListeners(moveUpCtrl,"moveUpCtrl");
    moveUpCtrl.addClassName('playlist-item-up');
    moveUpCtrl.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
//    goog.events.listen(control, goog.ui.Component.EventType.ACTION,
//        function (e) {
//            
//            alert("MOVE UP");
//        });    
    
    container.addChild(moveUpCtrl, true);
    
    //button down
    var moveDownCtrl = new goog.ui.Control();
    moveDownCtrl.addClassName('playlist-item-down');
    //console.log("move down: " + moveDownCtrl);
    new goog.ui.Tooltip(moveDownCtrl.getElement(), "posunout nahoru");
    moveDownCtrl.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
    container.addChild(moveDownCtrl, true);
    
    //button remove
    var removeCtrl = new goog.ui.Control();
    removeCtrl.addClassName('playlist-item-remove');
    removeCtrl.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
    container.addChild(removeCtrl, true);
    console.log("track container: " + container);
    return container;
};

kramerius.audio.ui.playlist.TrackComponent.prototype.getContainer = function(){
    return this.container_;
}
